package com.tedu.bill;

import java.util.Arrays;

/**
 * Author：毕龙
 * Date: 2024/3/31 11:21
 */
public class TestArrayCopy {
    public static void main(String[] args) {
        //数组复制
        int[] arr = {1,2,3,4,5};
        //调用函数
        int[] b = copyOrigin(arr);

        //数组的遍历
        System.out.println(Arrays.toString(b));
        b = copyRelative(arr);
        System.out.println(Arrays.toString(b));
        b = copyRelative(arr);
        System.out.println(Arrays.toString(b));

    }
    //最原始复制
    public static int[] copyOrigin(int[] a){
        int[] b = new int[a.length];
        for (int i = 0; i < b.length; i++) {
            b[i] = a[i];
        }
        return b;
    }

    //系统提供功能
    public static int[] copyRelative(int[] a){

        /**
         *
         Params:
         src – the source array.  源数组
         srcPos – starting position in the source array. 源数组的起始位置
         dest – the destination array. 目标数组
         destPos – starting position in the destination data. 目标数组的起始位置
         length – the number of array elements to be copied. 复制的元素长度
         */
        //五个参数
        int[] b = new int[a.length];
        System.arraycopy(a,0,b, 0, a.length);
        return b;
    }
    //工具类提供的功能
    public static int[] copyNative(int[] a){
        //把系统提供的功能简化
        //要复制的源数组
        //复制新的长度
        /**
         * Params:
         * original – the array to be copied
         * newLength – the length of the copy to be returned
         */
        return Arrays.copyOf(a,a.length);
    }
}
